package com.example.farmer.Seller_Home;

import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.farmer.Adapter.Product.MyProductAdapter;
import com.example.farmer.Database.ProductPublishDatabase;
import com.example.farmer.Entity.ProductPost;
import com.example.farmer.R;

import java.util.List;

public class ActivityMyGoods extends AppCompatActivity {
    private ProductPublishDatabase productPublishDatabase;
    private MyProductAdapter adapter;
    private List<ProductPost> productPostList;
    private RecyclerView recyclerView;
    private TextView textViewPostContent;




    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_goods);

        textViewPostContent = findViewById(R.id.poster_not_published);

        productPublishDatabase = ProductPublishDatabase.getInstance(this);
        productPostList = productPublishDatabase.getPostsByPushType("出售");

        // 这里可以设置Adapter来显示列表数据
        recyclerView = findViewById(R.id.rv_goods);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new MyProductAdapter(productPostList, this);
        recyclerView.setAdapter(adapter);

        updateUiWithPosts();
    }

    private void updateUiWithPosts() {
        // 如果posts不为空，则通知适配器数据已更改
        if (productPostList != null && !productPostList.isEmpty()) {
            // 假设PostAdapter实现了相应的方法来更新数据
            adapter = (MyProductAdapter) recyclerView.getAdapter();
            productPostList = productPublishDatabase.getPostsByPushType("出售");
            if (adapter != null) {
                adapter.updatePosts(productPostList);
            }
        } else {
            textViewPostContent.setText("你还没有发布货品哦"); // 假设您有一个TextView来显示消息
        }
    }
}
